Create a New Tab (deprecated)
Before you read on, please know that extensibility in our webforms framework is deprecated and will be removed soon. Please read here for a little more context.
This article will teach you how to add a tab to an existing page across all of the CMSs that Ucommerce supports from a single codebase. The sample app project has an example how to do this.
Note that tabs are call sections in the code.
The Page Builder Pipeline
Prior to executing the page builder pipeline Ucommerce will setup all default tabs. This means that you can modify the default tabs in regards to: remove a default tab, add additional tabs and add addition buttons to the default tabs.
Save & Delete Events
If your user control needs to react when the entity is either saved or deleted then your user control needs to inherit from UCommerce.Presentation.Web.ViewEnabledControl
You’ll find a list of the most commonly used views here:
View | Interface |
---|---|
Edit product catalog group | Ucommerce.Presentation.Views.Catalog.IEditProductCatalogGroupView |
Edit product catalog | Ucommerce.Presentation.Views.Catalog.IEditProductCatalogView |
Edit category | Ucommerce.Presentation.Views.Catalog.IEditCategoryView |
Edit product | Ucommerce.Presentation.Views.Catalog.IEditProductView |
View order | Ucommerce.Presentation.Views.Orders.IViewOrderGroupView |
There are one for each view in Ucommerce, grouped under the area they belong to in the namespace:
Ucommerce.Presentation.Views
From your user control, there are three events that are of interest to subscribe to depending on your view type. you'd be interested in the following generic interface:
event System.EventHandler`1[Ucommerce.Presentation.Views.Catalog.EntityCommandEventArgs`1[T]] Saving event System.EventHandler`1[Ucommerce.Presentation.Views.Catalog.EntityCommandEventArgs`1[T]] Save event System.EventHandler`1[Ucommerce.Presentation.Views.Catalog.EntityCommandEventArgs`1[T]] Saved
There's an equivalent for all other types as well.
The Saving event is raised before the main entity (e.g. Product on IEditProductView) is saved, and the Saved event is raised after the main entity has been saved. If you want to modify the main entity before it is saved, do it at the Saving event. The EntityCommandEventArgs
For some views, you can also subscribe to these three events, which are raised when deleting the entity – they are handy for doing some cleanup:
event System.EventHandler`1[Ucommerce.Presentation.Views.Catalog.EntityCommandEventArgs`1[T]] Deleting event System.EventHandler`1[Ucommerce.Presentation.Views.Catalog.EntityCommandEventArgs`1[T]] Delete event System.EventHandler`1[Ucommerce.Presentation.Views.Catalog.EntityCommandEventArgs`1[T]] Deleted
From your user control, you also have access to the view itself using the View-property on the ViewEnabledControl
Create a new PipelineTask
The code snippet below is a pipeline task that runs on the generic type 'UCommerce.Presentation.UI.SectionGroup, UCommerce.Presentation'. It hooks in a new tab in the settings page using PageBuilder pipeline .
public class AboutTabInSettings : Ucommerce.Pipelines.IPipelineTask<Ucommerce.Presentation.UI.SectionGroup> { public AboutTabInSettings() { } public PipelineExecutionResult Execute(SectionGroup sectionGroup) { //If the view is not the one that we want to hook into, then do nothing if (sectionGroup.GetViewName() != Ucommerce.Constants.UI.Pages.Roots.Settings) return PipelineExecutionResult.Success; var section = BuildSection(sectionGroup); sectionGroup.AddSection(section); //Sets the new tab as default tab when the settings node is clicked sectionGroup.ActiveTabId = sectionGroup.Sections.IndexOf(section); return PipelineExecutionResult.Success; } private Section BuildSection(SectionGroup sectionGroup) { var section = new Section { Name = "About", ID = sectionGroup.CreateUniqueControlId() }; var control = sectionGroup.View.LoadControl("/Apps/SampleApp/About.ascx"); //Get the name of the control if it implements the INamed inferface if (control is INamed) section.Name = (control as INamed).Name; section.AddControl(control); return section; } }
Finding the Right Page
To help you find the right page and tab, the constants class contains information that can be used to identify pages.
Below is an example of how to use the constants to identify that the current page is the one shown when you click on the settings node in the tree.
//If the view is not the one that we want to hook into, then do nothing if (sectionGroup.GetViewName() != Ucommerce.Constants.UI.Pages.Roots.Settings) return PipelineExecutionResult.Success;
Adding Your Tab
The content on your tabs must be an ASP.NET user control (.ascx) and can output any given html you want (including angular directives). If you're interested in how to achieve that, please read How to add resources through ClientDependency
Before you can add your tab to a page, you have to actually create your tab. The example below is taken from the The sample app project and it shows how you can create a tab.
var section = new Section { Name = "About", ID = sectionGroup.CreateUniqueControlId() }; var control = sectionGroup.View.LoadControl("/Apps/SampleApp/About.ascx"); //Get the name of the control if it implements the INamed inferface if (control is INamed) section.Name = (control as INamed).Name; section.AddControl(control);
As you can see in the example if your user control implements either the INamed or INamedReadOnly interface, you can leverage that to get the title of the tab.
Now that you have found the page that your want to add your tab to and you have created your tab, it's as easy as shown in the example to add your tab to the page.
Save and Delete Buttons
You may want to add the Ucommerce save or delete button to your tab. All you need to do is add the appropriate placeholder button to your section's menu and Ucommerce will provide your tab with the button that you want.
If the page, that you want your tab on, doesn't have the Ucommerce button that you want to add then the button won't be added.
Below is an example on how to add both the Ucommerce save button and delete to a tab.
section.Menu.AddMenuButton(new Ucommerce.Presentation.Web.Controls.SaveButtonPlaceholder()); section.Menu.AddMenuButton(new Ucommerce.Presentation.Web.Controls.DeleteButtonPlaceholder());
Register the task in the PageBuilder Pipeline
The example below shows how to register a pipeline task and how to use partial components to add the pipeline task to the PageBuilder pipeline.
<configuration> <components> <!-- Adds the AboutTabInSettings pipeline task into the page builder pipeline --> <partial-component id="PageBuilder"> <parameters> <tasks> <array> <item insert="last">${SampleApp.PageBuilder.AboutTabInSettings}</item> </array> </tasks> </parameters> </partial-component> <!-- This is the configuration of the AboutTabInSettings example --> <!-- This pipeline task that adds a tab to the settings node in the Ucommerce back office --> <component id="SampleApp.PageBuilder.AboutTabInSettings" service="Ucommerce.Pipelines.IPipelineTask`1[[Ucommerce.Presentation.UI.SectionGroup, Ucommerce.Presentation]], Ucommerce" type="SampleApp.Extensions.UI.Tab.AboutTabInSettings, SampleApp.Extensions"> <parameters> <!-- Inject a specific configuration of the TabConfiguration by using the component id --> <tabConfiguration>${SampleApp.TabConfiguration}</tabConfiguration> </parameters> </component> </components> </configuration>